package com.blog.service.impl;

import com.blog.service.SendMailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class SendMailServiceImpl implements SendMailService {

    @Autowired
    private JavaMailSender javaMailSender;

    //发送人
    private String from = "2743999033@qq.com";

    /**
     * 发送邮箱验证码
     * @param userEmail
     * @param code
     */
    @Override
    public void sendUserMail(String userEmail, String code) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from + "(来自CSDNN的邮件)");
        message.setTo(userEmail);
        message.setSubject("来自CSDNN的邮件" + "");
        message.setText("您的验证码为：" + code + "。请您妥善保管，不要泄露。");
        javaMailSender.send(message);
    }
}
